; heap-sort.ss  -- Jens Axel Soegaard

; The example from the doc.

(require "../heap.ss")

(use-heap (instantiate-heap splay-heap@ integers@))

(define (heap-sort l)
  (heap->list (list->heap l)))

(define (list->heap l)
  (foldl xinsert empty l))

(define (heap->list H)
  (define (loop H l)
    (if (empty? H)
        l
        (loop (delete-min H) (cons (find-min H) l))))
  (loop H '()))

(heap-sort '(3 1 4 1 5 9))
